/**
 * Copyright ©2016-2020 northkingbpo Corporation, All Rights Reserved
 * http://www.northkingbpo.net/
 */
package com.north.king.profile.http.client.resttemplate.server.multi;

import com.north.king.profile.http.client.resttemplate.server.data.CreateConditionData;
import com.north.king.profile.http.client.resttemplate.server.remote.RedisClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StopWatch;

import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 * class info
 *
 * @author hujia
 * @date 2018/12/10 11:05
 */
@Slf4j
public class MultiClientDesignated extends Thread {

    private final RedisClient redisClient;
    private final CreateConditionData createConditionData;
    private final int number;

    private final static int NUM = 20;

    public MultiClientDesignated(RedisClient redisClient, CreateConditionData createConditionData, int num) {
        this.redisClient = redisClient;
        this.createConditionData = createConditionData;
        this.number = num;

    }

    @Override
    public void run() {
        Map<String,String> condition=createConditionData.conditionDesignated(number % 20);
        for (int i = 0; i < NUM; ++i) {
            try {
                StopWatch watch = new StopWatch(currentThread().getName() + "|" + i);
                watch.start();
                redisClient.recommendedByPerson(condition);
                watch.stop();
                log.info(watch.shortSummary());
            } catch (Exception e) {
                log.error("recommended is error." + e.toString());
            }
        }
    }
}
